package biostienda.servlet;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import biostienda.excepcion.DAOExcepcion;
import biostienda.modelo.Transaccion;
import biostienda.negocio.GestionCategorias;
import biostienda.negocio.GestionTransaccion;

/**
 * Servlet implementation class RegistroTransaccionServlet
 */
@WebServlet("/RegistroTransaccionServlet")
public class RegistroTransaccionServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public RegistroTransaccionServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		
		int pub = 1;
		
		String tra = request.getParameter("transaccion");
		String usu = request.getParameter("tipousuario");
		String can = request.getParameter("cantidad");
		String com = request.getParameter("comentario");
		
		Transaccion b = new Transaccion();
		GestionTransaccion negocio = new GestionTransaccion();
		int sa=b.getIdTransaccion();
		
		//int id = b.getIdTransaccion();
		int usuario= Integer.parseInt(usu);
		int cantidad= Integer.parseInt(can);
		//int id = Integer.parseInt(b.getIdTransaccion());

		try {
            negocio.insertar( tra, pub, usuario,sa ,cantidad,com );
            response.sendRedirect(request.getContextPath()  + "/registrovalido.jsp");
            
    } catch (DAOExcepcion q) {

		RequestDispatcher rd = request.getRequestDispatcher("registrotransaccion.jsp");
		rd.forward(request, response);
}

	}

}
